import { JsonUtil } from '../common/JsonUtil';

describe('JsonUtil', () => {
  it('jsonToObject', () => {
    const jsonString = '{"id": 1, "name": "Alice"}';
    const user = JsonUtil.jsonToObject<User>(jsonString);
    expect(user).toEqual({ id: 1, name: 'Alice' });
  });
  it('jsonToMap', () => {
    const jsonString = '{"id": 1, "name": "Alice"}';
    const userMap = JsonUtil.jsonToMap(jsonString);
    expect(userMap.get('name')).toEqual('Alice');
  });
  it('objectToJson', () => {
    const user: User = { id: 1, name: 'Alice' };
    const jsonString = JsonUtil.toJsonString(user);
    expect(jsonString).toEqual('{"id":1,"name":"Alice"}');
  });
});

class User {
  id = 0;
  name = '';
}
